<template>
  <div class="nav-header">
    <i
      class="fold-menu"
      @click="handleFoldClick"
      :class="isFold ? 'el-icon-s-fold' : 'el-icon-s-unfold'"
    ></i>
    <div class="content">
      <nav-breadcrumb :breadcrumbs="breadcrumbs"></nav-breadcrumb>
      <user-info />
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref, computed, watchEffect } from 'vue'
import userInfo from './user-info.vue'
import NavBreadcrumb from '@/base-ui/breadcrumb/index'

import { useStore } from '@/store'
import { useRoute } from 'vue-router'
import { pathMapBreadcrumb } from '@/utils/map-menus'

import { IBreadcrumb } from '@/base-ui/breadcrumb/types'

export default defineComponent({
  components: { userInfo, NavBreadcrumb },
  emits: ['handleFoldClick'],
  setup(props, { emit }) {
    const store = useStore()
    const route = useRoute()

    const isFold = ref(true) //

    const breadcrumbs = computed<IBreadcrumb[]>(() => {
      return pathMapBreadcrumb(store.state.login.userMenus, route.path)
    })

    const handleFoldClick = () => {
      emit('handleFoldClick', isFold.value)
      isFold.value = !isFold.value
    }

    return {
      handleFoldClick,
      isFold,
      breadcrumbs
    }
  }
})
</script>

<style scoped lang="less">
.nav-header {
  display: flex;
  width: 100%;
  align-items: center;
  .fold-menu {
    font-size: 30px;
    cursor: pointer;
  }

  .content {
    display: flex;
    align-items: center;
    flex: 1;
    justify-content: space-between;
    padding: 0 0 0 10px;
  }
}
</style>
